﻿<%@ Page Language="C#" MasterPageFile="~/User/MasterPage.master" AutoEventWireup="true" CodeFile="userlist.aspx.cs" Inherits="User_userlist" Title="无标题页" %>

<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
        var template = '<span style="color:{0};">{1}</span>';

        var Shenhe = function (value) {
            if(value==0){return String.format(template,'red', '员工');}
            if(value==1){return String.format(template,'green', '领导');}
            if(value==2){return String.format(template,'blue', '系统管理员');}
        }
        
        var Shenhe2 = function (value) {
            if(value==0){return String.format(template,'red', '禁用');}
            if(value==1){return String.format(template,'green', '正常');}             
        }
        var Shenhe3 = function (value) {
            if(value==1){return String.format(template,'black', '公司领导');}
            if(value==2){return String.format(template,'black', '办公室');}
            if(value==3){return String.format(template,'black', '人事部');}
            if(value==4){return String.format(template,'black', '财务部');}
            if(value==5){return String.format(template,'black', '生产技术部');}
            if(value==6){return String.format(template,'black', '安全监察部');}
            if(value==7){return String.format(template,'black', '营销部');}
            if(value==8){return String.format(template,'black', '调度所');}
            if(value==9){return String.format(template,'black', '变电管理所');}
            if(value==10){return String.format(template,'black', '配电营业所');}
            if(value==11){return String.format(template,'black', '计量组');}
            if(value==12){return String.format(template,'black', '大客户组');}
            if(value==13){return String.format(template,'black', '用电稽查组');}
            if(value==14){return String.format(template,'black', '负控组');}
            if(value==15){return String.format(template,'black', '秀山供电所');}
            if(value==16){return String.format(template,'black', '四街供电所');}
            if(value==17){return String.format(template,'black', '九街供电所');}
            if(value==18){return String.format(template,'black', '河西供电所');}
            if(value==19){return String.format(template,'black', '杨广供电所');}
            if(value==20){return String.format(template,'black', '高大供电所');}
            if(value==21){return String.format(template,'black', '管理员');}
        }
        var Shenhe4 = function (value) {
            return String.format(template,'black', '******');           
        }
    </script>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CXDB %>" 
        SelectCommand="SELECT [id], [deptname] FROM [CX_SYS_Dept]">

    </asp:SqlDataSource>
    <ext:Store ID="Store2"  DataSourceID="SqlDataSource2"   runat="server">
    <Reader>
        <ext:JsonReader ReaderID="id">
            <Fields>
                <ext:RecordField Name="deptname" Type="String"></ext:RecordField>
                <ext:RecordField Name="id" Type="Int"></ext:RecordField>
            </Fields>
        </ext:JsonReader>
    </Reader>
    </ext:Store>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CXDB %>" 
        DeleteCommand="DELETE FROM [CX_UserBase] WHERE [uID] = @uID" 
        InsertCommand="INSERT INTO [CX_UserBase] ([username], [passWD], [status], [LevelID],[depid]) VALUES (@username, @passWD, @status, @LevelID,@depid)" 
        SelectCommand="SELECT [uID], [username], [passWD], [status], [LevelID],[depid] FROM [cx_userbase] ORDER BY [uID] DESC" 
        UpdateCommand="UPDATE [CX_UserBase] SET [username] = @username, [passWD] = @passWD, [status] = @status, [depid] = @depid, [LevelID] = @LevelID WHERE [uID] = @uID">
        <DeleteParameters>
            <asp:Parameter Name="uID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="username" Type="String" />
            <asp:Parameter Name="passWD" Type="String" />
            <asp:Parameter Name="status" Type="Int32" />
            <asp:Parameter Name="LevelID" Type="Int32" />
            <asp:Parameter Name="depid" Type="Int32" />
            <asp:Parameter Name="uID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="username" Type="String" />
            <asp:Parameter Name="passWD" Type="String" />
            <asp:Parameter Name="status" Type="Int32" />
            <asp:Parameter Name="depid" Type="Int32" />
            <asp:Parameter Name="LevelID" Type="Int32" />
        </InsertParameters>
    </asp:SqlDataSource>
    <ext:Store ID="Store1" DataSourceID="SqlDataSource1" runat="server">
        <Reader>
            <ext:JsonReader ReaderID="uID">
                <Fields>
                    <ext:RecordField Name="uID" Type="Int"></ext:RecordField>
                    <ext:RecordField Name="username" Type="String"></ext:RecordField>
                    <ext:RecordField Name="passWD" Type="String"></ext:RecordField>
                    <ext:RecordField Name="deptname" Type="String"></ext:RecordField>
                    <ext:RecordField Name="LevelID" Type="Int"></ext:RecordField>
                    <ext:RecordField Name="status" Type="Int"></ext:RecordField>
                    <ext:RecordField Name="depid" Type="Int"></ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Panel ID="Panel1" runat="server"  AutoHeight="true" Header="false" Layout="Fit">
                            <body>
                                <ext:GridPanel 
                                    ID="GridPanel1" 
                                    runat="server"  
                                    Title="员工数据"  
                                    StoreID="Store1" 
                                    Border="false"
                                     AutoHeight="true" 
                                    Icon="Lorry">
                                    <ColumnModel runat="server">
                                        <Columns>
                                            <ext:Column 
                                                ColumnID="uID" 
                                                DataIndex="uID" 
                                                Header="用户编号"> 
                                            </ext:Column>
                                            <ext:Column DataIndex="username" Header="用户名">
                                                <Editor>
                                                    <ext:TextField runat="server" />
                                                </Editor>
                                            </ext:Column>
                                            <ext:Column DataIndex="passWD" Header="密码">
                                            <Renderer Fn="Shenhe4" />
                                                <Editor>
                                                    <ext:TextField Text="" InputType="Password"  runat="server" />                                                    
                                                </Editor>
                                            </ext:Column>
                                            <ext:Column DataIndex="depid" Header="部门">
                                            <Renderer Fn="Shenhe3" />
                                               <Editor>
                                                <ext:ComboBox ID="ComboBox2" runat="server" DataIndex="depid">
                                                        <Items>
                                                            <ext:ListItem Text='公司领导' Value='1' /> 
                                                            <ext:ListItem Text='办公室' Value='2' /> 
                                                            <ext:ListItem Text='人事部' Value='3' /> 
                                                            <ext:ListItem Text='财务部' Value='4' /> 
                                                            <ext:ListItem Text='生产技术部' Value='5' /> 
                                                            <ext:ListItem Text='安全监察部' Value='6' /> 
                                                            <ext:ListItem Text='营销部' Value='7' /> 
                                                            <ext:ListItem Text='调度所' Value='8' /> 
                                                            <ext:ListItem Text='变电管理所' Value='9' /> 
                                                            <ext:ListItem Text='配电营业所' Value='10' /> 
                                                            <ext:ListItem Text='计量组' Value='11' /> 
                                                            <ext:ListItem Text='大客户组' Value='12' /> 
                                                            <ext:ListItem Text='用电稽查组' Value='13' /> 
                                                            <ext:ListItem Text='负控组' Value='14' /> 
                                                            <ext:ListItem Text='秀山供电所' Value='15' /> 
                                                            <ext:ListItem Text='四街供电所' Value='16' /> 
                                                            <ext:ListItem Text='九街供电所' Value='17' /> 
                                                            <ext:ListItem Text='河西供电所' Value='18' /> 
                                                            <ext:ListItem Text='杨广供电所' Value='19' /> 
                                                            <ext:ListItem Text='高大供电所' Value='20' /> 
                                                            <ext:ListItem Text='管理员' Value='21' /> 
                                                        </Items>
                                                    </ext:ComboBox>
                                               </Editor>
                                            </ext:Column>                    
                                            <ext:Column DataIndex="LevelID" Header="级别">
                                            <Renderer Fn="Shenhe" />
                                                <Editor>
                                                    <ext:ComboBox runat="server" DataIndex="LevelID">
                                                        <Items>
                                                            <ext:ListItem Text="员工" Value="0" />
                                                            <ext:ListItem Text="领导" Value="1" />
                                                            <ext:ListItem Text="系统管理员" Value="2" />
                                                        </Items>
                                                    </ext:ComboBox>
                                                </Editor>
                                            </ext:Column>   
                                            <ext:Column DataIndex="status" Header="状态">
                                            <Renderer Fn="Shenhe2" />
                                                <Editor>
                                                    <ext:ComboBox ID="ComboBox1" runat="server" DataIndex="status">
                                                        <Items>
                                                            <ext:ListItem Text="禁用" Value="0" />
                                                            <ext:ListItem Text="正常" Value="1" /> 
                                                        </Items>
                                                    </ext:ComboBox>
                                                </Editor>
                                            </ext:Column>  
                                                            
                                        </Columns>
                                    </ColumnModel>                                    
                                    <SelectionModel>
                                        <ext:RowSelectionModel runat="server" />
                                    </SelectionModel>
                                    <BottomBar>
                                        <ext:PagingToolbar 
                                            runat="server" 
                                            PageSize="10" 
                                            StoreID="Store1" 
                                            DisplayInfo="false" 
                                            />
                                    </BottomBar>
                                    <SaveMask ShowMask="true" />
                                    <LoadMask ShowMask="true" />
                                <Buttons>
                                <ext:Button ID="btnSave" runat="server"  Text="保存修改" Icon="Disk">
                                    <Listeners>
                                        <Click Handler="#{GridPanel1}.save();" />                                        
                                    </Listeners>
                                </ext:Button>
                                 <ext:Button ID="btnInsert" runat="server"  Text="添加" Icon="Add">
                                    <Listeners>
                                        <Click Handler="#{GridPanel1}.insertRecord(0, {});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.startEditing(0, 0);" />
                                    </Listeners>
                                </ext:Button>
                                <ext:Button ID="btnRefresh" runat="server"  Text="刷新数据" Icon="ArrowRefresh">
                                    <Listeners>                                    
                                        <Click Handler="#{GridPanel1}.reload();" />
                                        
                                    </Listeners> 
                                </ext:Button>                         
                            </Buttons>
                                </ext:GridPanel>
                            </body>
                            
                        </ext:Panel>
</asp:Content>

